/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package module;

import java.util.ArrayList;
import wargame.dao.CompanyDAO;
import wargame.entity.Company;

/**
 *
 * @author Alvin Chua
 */
public class GenerateCompany {

    public static Company generateCompany(String name) {

        Company newCompany = new Company();

        int programming_count = (int) Math.random() * 3;
        programming_count = (programming_count == 0)? 1 : programming_count;
        int programming = 0;
        while (programming_count > programming) {
            //generate random numbers to multiply the company's preference
            double amount = Math.random() * 10;
            double skill = Math.random();

            //generating preference for the project
            if (skill > 0.8 && amount > 5) {
                newCompany.setPreferred_skill_dot_net((int) amount + 5);
                programming++;
            } else if (skill > 0.6 && amount > 5) {
                newCompany.setPreferred_skill_c_sharp((int) amount + 4);
                programming++;
            } else if (skill > 0.4 && amount > 5){
                newCompany.setPreferred_skill_jsp((int) amount + 4);
                programming++;
            } else if (skill > 0.2 && amount > 5){
                newCompany.setPreferred_skill_php((int) amount + 2);
                programming++;
            } else if (skill > 0 && amount > 5) {
                newCompany.setPreferred_skill_ruby((int) amount);
                programming++;
            }
            
        }

        int database = 0;
        while (database < 1) {
            double amount = Math.random() * 10;
            double skill = Math.random();

            if (skill > 6 && amount > 5) {
                newCompany.setPreferred_skill_mysql((int) amount);
                database++;
            } else if (skill > 3 && amount > 5) {
                newCompany.setPreferred_skill_mssql((int) amount + 2);
                database++;
            } else if (skill > 0 && amount > 5) {
                newCompany.setPreferred_skill_oracle((int) amount + 3);
                database++;
            }
            
        }

        double economic_sensitivity = Math.random() + 0.1;
        newCompany.setEconomic_sensitivity(economic_sensitivity);

        newCompany.setBudget((int) (Math.random() * 10000000));

        newCompany.setName(name);

        int id = CompanyDAO.insertCompany(newCompany);

        newCompany.setCompany_id(id);

        return newCompany;
    }
}
